package com.totem.customer.controller;

import com.totem.admin.service.IAdminCustomerService;
import com.totem.base.CacheHolder;
import com.totem.base.constants.CacheConstants;
import com.totem.base.constants.CommonConstants;
import com.totem.base.constants.ErrorCode;
import com.totem.base.exception.BaseException;
import com.totem.base.model.PageVO;
import com.totem.base.model.Result;
import com.totem.base.mybatis.UserIdContext;
import com.totem.base.mybatis.controller.BaseController;
import com.totem.customer.api.ITCustomerServiceApi;
import com.totem.customer.mapper.TLoginJournalMapper;
import com.totem.customer.model.TCustomers;
import com.totem.customer.model.TLoginJournal;
import com.totem.customer.serivce.ITCustomerService;
import com.totem.customer.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class CustomerController extends BaseController<ITCustomerService, TCustomers> implements ITCustomerServiceApi {
    @Autowired
    private IAdminCustomerService iAdminCustomerService;

    @Override
    public Result<Boolean> create(CustomerCreateVO vo) {
        boolean result = service.createCustomer(vo);
        return Result.result("创建客户信息成功", "创建客户信息失败", result);
    }

    @Override
    public Result<CustomerProfileVO> profile() {
        return Result.success(service.profile());
    }

    @Override
    public Result<CustomerVO> getVoById(Long id) {
        return Result.success(service.getVoById(id));
    }

    @Override
    public Result<CustomerLoginVO> login(CustomerLoginVO vo) {
        return Result.success(iAdminCustomerService.login(vo));
    }

    @Override
    public Result<Boolean> logout(CustomerLogoutVO vo) {
        return Result.success(service.logout());
    }

    @Override
    public Result<Boolean> resetPassword(ResetPasswordVO vo) {
        return Result.success(service.resetPassword(vo));
    }

    @Override
    public Result<Boolean> updateTxPassword(UpdateTxPasswordVO vo) {
        return Result.success(service.updateTxPassword(vo));
    }

    @Override
    public Result<InviteVO> searchByEmailOrMobile(SearchByEmailOrMobileVO vo) {
        return Result.success(service.searchByEmailOrMobile(vo));
    }

    @Override
    public Result<Boolean> registerCheck(RegisterCheckVO vo) {
        return Result.success(service.registerCheck(vo));
    }

    @Override
    public Result<TeamInfoVO> teamInfo(TeamInfoVO vo) {
        Long customerId = UserIdContext.getUserId();
        if(vo.getCustomerId()!=null)
            customerId = vo.getCustomerId();
        return Result.success(service.teamInfo(customerId));
    }
}
